new Vue({
	el: "body",
	data: {
		shop: [],
		addresslist: [],
		user: {},
		unmoney: false
	},
	methods: {
		confirm: function() {
			var todo = AV.Object.createWithoutData('ELM_order', geturlitem(location.search, "orderid"));
			// 修改属性
			todo.set('if_pay', true);
			// 保存到云端
			todo.save();
			//User
			var currentUser = AV.User.current();
			var userid = currentUser.id;
			var money = this.user.Money;
			var total = this.shop[0].attributes.shop_sendprice * 1 + this.shop[0].attributes.total;
			var integral = (this.user.integral * 1 + parseInt(total)) + "";

			if(money - total < 0) { //余额不足
				this.unmoney = true;
				console.log(total);
			} else {
				var todo1 = AV.Object.createWithoutData('_User', userid);
				// 修改属性
				money = money * 1 - total * 1;
				todo1.set('isNewUser', false);
				todo1.set('integral', integral);
				todo1.set('Money', money);
				console.log(money);
				// 保存到云端
				todo1.save();
				location.href = "../Order/order.html";
			}

		},
		address: function() {
			location.href = "../address/address.html?orderid=" + geturlitem(location.search, "orderid");
		},
		Recharge: function() {
			location.href = "../Recharge/Recharge.html?orderid=" + geturlitem(location.search, "orderid");
		}
	},
	created: function() {
		init();
		var myurl = location.search;
		var orderid = geturlitem(myurl, "orderid");
		var shop = this.shop;
		var query = new AV.Query('ELM_order'); //订单表
		query.get(orderid).then(function(item) {
			shop.push(item);
		});
		var currentUser = AV.User.current();
		var userid = currentUser.id;
		this.userid = userid;
		var _this = this;
		var query1 = new AV.Query('_User'); //用户表
		query1.get(userid).then(function(user) {
			_this.user = user.attributes;
			console.log(user);
			for(var i = 0; i < user.attributes.address.length; i++) {
				var index = geturlitem(myurl, "index");
				_this.addresslist.push(user.attributes.address[index]);
			}
		})
	},
	beforeCompile: function() {
		this.loading = true;
	}
})